

package pers.ljf.escloud.service.modules.sys.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import pers.ljf.escloud.dao.entity.sys.SysLogEntity;
import pers.ljf.escloud.dao.mapper.sys.SysLogDao;
import pers.ljf.escloud.service.dto.Query;
import pers.ljf.escloud.service.modules.sys.SysLogService;
import pers.ljf.escloud.service.util.PageUtils;

import java.util.Map;


@Service("sysLogService")
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLogEntity> implements SysLogService {

    /**
     * 分页查询系统日志，参数若带username可以模糊匹配
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String)params.get("key");

        IPage<SysLogEntity> page = this.page(
            new Query<SysLogEntity>().getPage(params),
                new QueryWrapper<SysLogEntity>().like(StringUtils.isNotBlank(key), "username", key).orderByDesc("create_date")
        );

        return new PageUtils(page);
    }
}
